<?php

class CArr
{
	/**
	 * Element
	 *
	 * Lets you determine whether an array index is set and whether it has a value.
	 * If the element is empty it returns FALSE (or whatever you specify as the default value.)
	 *
	 * @access	public
	 * @param	string
	 * @param	array
	 * @param	mixed
	 * @return	mixed	depends on what the array contains
	 */
	
	public static function element($item, $array, $default = FALSE)
	{
		if (isset($array[$item]))
		{
			return $array[$item];
		}
		else
		{
			return $default;
		}
	}
	
	public static function ele($item, $array, $default = FALSE)
	{
		if (isset($array[$item]))
		{
			if (is_string($array[$item]))
			{
				return htmlspecialchars($array[$item],ENT_QUOTES);
			}
			else
			{
				return $array[$item];
			}
		}
		else
		{
			return $default;
		}
	}
	
	public static function key_exists($item, $array, $default = NULL)
	{
		if (isset($array[$item]))
		{
			return $item;
		}
		elseif ($default === NULL)
		{
			return key($array);
		}
		else
		{
			return $default;
		}
	}
}
